import { Space } from 'antd'
import { useEffect, useState } from 'react'
import styles from './style.less'

const CheckActon = (props) => {

    const {
        check = false,
        onChange,
        label
    } = props

    useEffect(() => {
        setIsCheck(check)
    },[check])

    const [isCheck,setIsCheck] = useState(check)

    return <Space
        className={isCheck ? styles.checkedActionClass : styles.unCheckedActionClass}
        onClick={() => {
            let newValue = !isCheck;
            setIsCheck(newValue)
            if (onChange) {
                onChange(newValue)
            }
        }}
    >
        {label}
    </Space>
}

export default CheckActon;